package com.dcm.groupbuy.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.groupbuy.bo.NumberBo;
import com.dcm.groupbuy.entity.GroupOrderEntity;
import com.dcm.groupbuy.service.GroupOrderService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 牛浩
 */
@Api(tags = "GroupOrderController")
@RestController
@CrossOrigin
@RequestMapping("/GroupOrderController")
@EnableResponseBodyAdvice
public class GroupOrderController {
    @Autowired
    private GroupOrderService groupOrderService;

    /**
     * 查询参与人数和成团数量
     */
    @ApiOperation("查询参与人数和成团数量")
    @GetMapping("/searchNum")
    public NumberBo searchNum(){
        return groupOrderService.searchNum();
    }
    /**
     * 查询所有
     * @return
     */
    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public List<GroupOrderEntity> findAll(){
        return groupOrderService.findAll();
    }

    /**
     * 模糊查询
     * @param groupState
     * @return
     */
    @ApiOperation("模糊查询")
    @GetMapping("/search")
    public List<GroupOrderEntity> search(@RequestParam(value = "groupState",required =false) Integer groupState){
        return groupOrderService.search(groupState);
    }

    /**
     * 添加拼团
     * @param groupOrderEntity
     */
    @ApiOperation("添加拼团")
    @PostMapping("/insertGroupOrder")
    public void insertGroupOrder(@RequestBody GroupOrderEntity groupOrderEntity){
        groupOrderService.insertGroupOrder(groupOrderEntity);
    }

    /**
     * 根据时间类型查询商品
     * @param state
     */
    @ApiOperation("根据时间类型查询商品")
    @GetMapping("/dateSearch")
    public List<GroupOrderEntity> dateSearch(@RequestParam(value = "state",required = false) Integer state ){
        return groupOrderService.dateSearch(state);
    }

    @ApiOperation("分页")
    @GetMapping("/findPage")
    public PageInfo<GroupOrderEntity> findPage(@RequestParam(value = "currentPage", required = false) Integer currentPage,
                                             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return groupOrderService.findPage(currentPage, pageSize);
    }
}